# 1、建立连接，连接池
# 2、执行sql
# 3、commit
# 4、关闭连接


import pymysql
# connect=pymysql.connect(
#     host="",
#     user="",
#     password="",
#     port="",
#     db=""
# )#自动提交，戳情使用

# query=connect.query("")
# cursor=connect.cursor()
# cursor.execute("")
# cursor.close()
# connect.close()


# mysql_info = {
#     "host":"118.24.3.40",
#     "user":"jxz",
#     "password":"123456",
#     "db":"jxz",
#     "port":3306,
#     "charset":"utf8",
#     "autocommit":True
# }

class mysqlUtil:
    def __init__(self,user,password,host,port,db):
        self.user=user
        self.password=password
        self.host=host
        self.prot=port
        self.db=db
        self.cursor=self.get_connection().cursor(pymysql.cursors.DictCursor)

    def get_connection(self):
        return pymysql.connect(
            host=self.host,
            user=self.user,
            password=self.password,
            port=self.prot,
            db=self.db
        )

    def query(self,sql):
        self.cursor.execute(sql)
        return self.cursor.fetchall()


    def __del__(self):
        self.cursor.close()

mysql=mysqlUtil("jxz","123456","118.24.3.40",3306,"jxz")
sql="select * from student"
mysql.query(sql)




